package benchmark;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.CountDownLatch;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/10/16 15:52
 */

public class BenchMarkMain {
    private int threadNum;
    private CountDownLatch latch;

    public static void main(String[] args) {

        Date now = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        System.out.println(sdf.format(now));



        BenchMarkMain main = new BenchMarkMain(1000);
        System.out.println("benchMark--------------start");
        long startTime = System.currentTimeMillis();
        main.benchMark();
        long endTime = System.currentTimeMillis();
        System.out.println("benchMark--------------end");
        System.out.println("耗时："+ (endTime-startTime)/1000);

    }

    public BenchMarkMain(int threadNum) {
        this.threadNum = threadNum;
        latch = new CountDownLatch(threadNum);
    }

    public void benchMark() {
        Thread[] threads = new Thread[threadNum];
        for (int i = 0; i < threadNum; i++) {
            //System.out.println(i);
            Thread thread = new Thread(new UserThread("UserThread" + i, latch));
            threads[i] = thread;
            thread.start();
            latch.countDown();
        }
        try {
            for (Thread thread : threads) {
                thread.join();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
